package com.todo.content.iface.frontend.request;

import com.todo.common.common.entity.CurrentUser;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @author azhebuxing
 * @date 2024/5/9 14:24
 * @description
 */
@Data
@Schema(title = "新增内容入参", description = "新增内容入参")
public class InsertContentParam {

    private CurrentUser _user;

    @Schema(name = "内容标题", description = "内容标题")
    private String title;

    @Schema(name = "内容信息", description = "内容信息")
    private String content;

    @Schema(name = "主图", description = "主图")
    private String mainImg;

    @Schema(name = "分类code", description = "分类code")
    private String classifyCode;

    @Schema(name = "关联图片列表", description = "关联图片列表")
    private List<String> relationImgList;

    @Schema(name = "是否私有", description = "是否私有")
    private Integer isPrivate;

    @Schema(name = "是否允许评论", description = "是否允许评论")
    private Integer allowComment;

    @Schema(name = "关联列表", description = "关联列表")
    private List<Relation> relationList;

    public boolean baseCheck() {
        if (title == null || content == null || mainImg == null || isPrivate == null || allowComment == null){
            return false;
        }
        if (CollectionUtils.isNotEmpty(relationList)){
            for (Relation relation : relationList) {
                if (relation.getRelationType() == null || relation.getRelationName() == null || relation.getRelationImg() == null || relation.getIsOutside() == null){
                    return false;
                }
            }
        }
        return true;
    }


    @Data
    public static class Relation {

        @Schema(title = "关联类型", description = "关联类型：各类业务数据")
        private Integer relationType;

        @Schema(title = "关联id", description = "关联id，内部存在")
        private Long relationId;

        @Schema(title = "关联名称", description = "关联名称")
        private String relationName;

        @Schema(title = "关联图片", description = "关联图片")
        private String relationImg;

        @Schema(name = "跳转url", description = "跳转url")
        private String jumpUrl;

        @Schema(name = "是否站外", description = "是否站外")
        private Integer isOutside;

        @Schema(name = "排序", description = "排序")
        private Integer sort;
    }
}
